package com.kili.cloud.shorturl.service.impl;

import com.kili.cloud.common.util.IpUtil;
import com.kili.cloud.shorturl.service.model.CustomerModel;
import com.kili.cloud.shorturl.service.CustomerService;
import com.kili.cloud.shorturl.service.TestService;
import com.kili.tools.redis.RedisUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: tom.liu
 * @date: 2019/6/14 10:06
 * @description: 测试service的实现
 */
@Service
public class TestServiceImpl implements TestService {
    private static Logger logger = LoggerFactory.getLogger(TestServiceImpl.class);

    @Autowired
    CustomerService customerService;

    @Autowired
    RedisUtils redisUtils;

    @Value("${server.port}")
    String port;

    @Override
    public String getClientIp(HttpServletRequest request) {
        logger.info("获取用户的ip");

        //测试mybatis引入
        CustomerModel customerModel = new CustomerModel();
        customerModel.setCustomerName("kilimall1");
        List<CustomerModel> customerModelList = customerService.selectBySelective(customerModel);

        //测试redis的存取
        redisUtils.set("customerModelList",customerModelList);
        redisUtils.expire("customerModelList", 60);
        List<CustomerModel> list = redisUtils.get("customerModelList", List.class);
        //测试前端-后端是否联通
        return IpUtil.getIpAddr(request);
    }

}
